﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XT.Model;
using XT.Repository;

namespace XT.BusinessService
{


    public class RoomService : IRoomService
    {
        private readonly IUow _uow;
        public RoomService(IUow uow)
        {
            _uow = uow;
        }

        public Room getRoomById(int id)
        {
            return _uow.RoomRepo.Find(id);
        }

        //public Room getRoomByName(int id)
        //{
        //    //return _uow.RoomRepo.FindAll<Room>(r => r.OrderByDescending(rr => rr.Room_Id)).Where<Room>(r => r.Room_Id == id).SingleOrDefault();
        //    //return _uow.RoomRepo.FindAll<Room>(o => o.OrderByDescending(c => c.Id));
        //}


        public IEnumerable<Room> getSomeRoomByArea(int areaId,int pageIndex,int pageSize)
        {
            return _uow.RoomRepo.FindAllByCriteria<Room>((c => c.Area_Id.Equals(areaId)), o => o.OrderByDescending(c => c.Id),pageIndex,pageSize);
        }

        public IEnumerable<Room> getSomeRoomByDistrict(int districtId, int pageIndex, int pageSize)
        {
            return _uow.RoomRepo.FindAllByCriteria<Room>((c => c.Area.District_Id.Equals(districtId)), o => o.OrderByDescending(c => c.Id), pageIndex, pageSize);
        }

        public IEnumerable<Room> getThreeRoomByDate()
        {
            return _uow.RoomRepo.FindAllByDate().Take(3);
        }


        public IEnumerable<Room> getThreeRoomByViews()
        {
            return _uow.RoomRepo.FindAllByViews().Take(3);
        }

        public IEnumerable<Room> showMoreHotRoom(int pageIndex,int pageSize)
        {
            return _uow.RoomRepo.FindAll<Room>(o => o.OrderByDescending(obj => obj.Viewed_Count), pageIndex, pageSize);
        }

        public IEnumerable<Room> showMoreNewRoom(int pageIndex, int pageSize)
        {
            return _uow.RoomRepo.FindAll<Room>(o => o.OrderByDescending(obj => obj.Room_Created_Date), pageIndex, pageSize);
        }
		public Room searchRoomByName(string txt)
		{
            return _uow.RoomRepo.ExecuteQuery(context => context.GetTable<Room>().SingleOrDefault(c => c.Room_Name.Equals(txt)));
		}
		
        public IEnumerable<Room> SuggestRooms(string txt)
		{
			return _uow.RoomRepo.FindAllByCriteria<Room>((c => c.Room_Name.ToLower().Contains(txt.ToLower())), o => o.OrderByDescending(c => c.Id));
		}


       
    }
}